package LeetCode.leetcode209;

public class Review3 {
    public int minSubArrayLen(int target, int[] nums) {
        int res = Integer.MAX_VALUE;
        int l = 0;
        int r = 0;
        int sum = 0;
        if (nums.length <= 0 && target <= 0) return 0;
        for (; r < nums.length; r++) {
            sum += nums[r];
            while (sum >= target) {
                int tmp = r - l + 1;
                res = Math.min(res, tmp);
                sum -= nums[l];
                l++;
            }
        }
        return res == Integer.MAX_VALUE ? 0 : res;
    }
}
